<?php include _include(ADMIN_PATH.'view/htm/header.inc.htm');?>

<div class="row">
	<div class="col-lg-12">
		<div class="btn-group mb-3" role="group">
			<?php echo admin_tab_active($menu['forum']['tab'], 'setting');?>
		</div>
		<div class="card">
			<div class="card-body">
				<form action="<?php echo url('forum-setting');?>" method="post" id="form">
					<div class="form-group row">
						<label class="col-sm-2 form-control-label">选择要修改的用户组：</label>
						<div class="col-sm-10">
							<select class="custom-select" name="gid">
								<?php foreach ($grouplist as $gid => $_group) { ?>
									<option value="<?php echo $_group['gid'] ?>"><?php echo $_group['name'] ?></option>
								<?php } ?>
							</select>
						</div>
					</div>

					<div class="form-group row">
						<label class="col-sm-2 form-control-label">每日的发帖额度(条/日)：</label>
						<div class="col-sm-10">
							<input type="number" name="day_quota" class="form-control" min="0" step="0.01" />
						</div>
					</div>

					<div class="form-group row">
						<label class="col-sm-2 form-control-label">超过额度的收费(角/条)：</label>
						<div class="col-sm-10">
							<input type="number" name="day_mony" class="form-control" />
						</div>
					</div>

					<div class="form-group row">
						<label for="inputPassword3" class="col-sm-2 form-control-label"></label>
						<div class="col-sm-10">
							<button type="submit" class="btn btn-primary btn-block" id="submit" data-loading-text="<?php echo lang('submiting');?>..."><?php echo lang('confirm');?></button>
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
</div>

<?php include _include(ADMIN_PATH.'view/htm/footer.inc.htm');?>

<script type="text/javascript">
	var grouplist = <?php echo json_encode($grouplist); ?>;
	var sidselect = $('select[name="gid"]');
	var day_quota = $('input[name="day_quota"]');
	var day_mony = $('input[name="day_mony"]');

	var gid = sidselect.val();

	day_quota.val(grouplist[gid]['day_quota']);
	day_mony.val(grouplist[gid]['day_mony']);

	sidselect.on('change',function(){
		var gid = sidselect.val();

		day_quota.val(grouplist[gid]['day_quota']);
		day_mony.val(grouplist[gid]['day_mony']);
	})

</script>

<script>
var jform = $('#form');
var jsubmit = $('#submit');

jform.base64_encode_file();
jform.on('submit', function() {
	jform.reset();
	jsubmit.button('loading');
	
	var postdata = jform.serializeObject();

	$.xpost(jform.attr('action'), postdata, function(code, message) {
		if(code == 0) {
			$.alert(message);
			jsubmit.button(message).delay(3000).button('reset');
		} else if(xn.is_number(code)) {
			alert(message);
			jsubmit.button('reset');
		} else {
			jform.find('[name="'+code+'"]').alert(message).focus();
			jsubmit.button('reset');
		}
	});
	return false;
});
</script>